'use strict';

const Controller = require('egg').Controller;

class ScoresController extends Controller {
  async create() {
    const {ctx}=this;
    let{name,stu,theory,skill}=ctx.request.body;
    if(!name||!stu||!theory||!skill){
        ctx.body={
            code:2,
            mes:'缺少参数'
        }
        return;
    }       
  }
  //获取
  async index(){
      const {ctx}=this;
      let {page=1,limit=5,search='',sortname='id',order=0}=ctx.query;
    let res=await ctx.service.scores.listscores(page.limit,search,sortname,order);

    ctx.body={
        code:0,
        ...res
    }



  }
  //编辑
  async update(){
      const {ctx}=this;
      let {name,stu,theory,skill,id}=ctx.request.body;
      let {id}=ctx.params;
      if(!name||!stu||!theory||!skill||!id){
        ctx.body={
            code:2,
            mes:'减少参数'
        }
        return;
      }
        //更新
  let res = await ctx.service.scores.updatescores(...ctx.request.body,id);
  ctx.body=res;
  }

  async destroy(){
      const {ctx}=this;
      let {id}=ctx.query;
      if(!id){
          ctx.body={
              code:2,
              mes:'少参数'
          }
          return
      }
      let res=await ctx.service.scores.delscores(id);
      if(res.affectedRows>0){
        ctx.body={
            code:0,
            mes:'删除成功'
        }
    }else{
        ctx.body={
            code:1,
            mes:'删除失败'
        }
    }
     ctx.body=res;
  }

  async getdate(){
      const {ctx}=this;
      let res=await ctx.service.getdate();
      ctx.body=res;
  }
    
}

module.exports = ScoresController;
